/******************************************
@Description:
	1.购卡支付成功后-统计银行/保险售卡金额
	2.购卡/充值卡复充支付成功后-统计银行存管金额
@Time : 2020/12/28 14:37
@Author :lixiaojun
交换机=pay.paysuc

*******************************************/

package main

import (
	"context"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/financial"
	"github.com/streadway/amqp"
)

func main() {
	rpcFinancial := new(financial.Bank).Init()
	defer rpcFinancial.Close()
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("financial.log.addSalesCardOrDepositAssets"))
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("financial.queue.addSalesCardOrDepositAssets"), func(msg amqp.Delivery) {
		orderSn := string(msg.Body)
		reply := false
		if err := rpcFinancial.StatisticsBankOrInsuranceSalesCardAssets(context.Background(), &orderSn, &reply); err != nil {
			utils.Logerr.Printf("购卡支付成功后-统计银行/保险售卡金额任务执行失败，订单号:%s ，错误信息: %s",orderSn, err.Error())
		}
		if err := rpcFinancial.StatisticsBankDepositAssets(context.Background(), &orderSn, &reply); err != nil {
			utils.Logerr.Printf("购卡支付成功后-统计银行存管金额任务执行失败，订单号:%s ，错误信息: %s",orderSn, err.Error())
		}
	})

	if err != nil {
		utils.Logerr.Printf("支付成功后，统计银行/保险售卡金额或存管金额任务执行错误, 错误信息: %s", err.Error())
	}
}
